package com.qys.livesMall.common.exception;

import com.qys.livesMall.common.exception.enums.ExceptionEnum;
import com.qys.livesMall.common.message.MessageServer;
import com.qys.livesMall.common.message.QysLang;
import com.qys.livesMall.common.utils.SpringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class QysException extends RuntimeException {
    private  String message;
    private  int code;

    public QysException() {
        super();
    }

    public QysException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public QysException(String message) {
        super(message);
        this.code = ExceptionEnum.INTERNAL_SERVER_ERROR.getCode();
        this.message = message;
    }

    public QysException(ExceptionEnum exceptionEnum) {
        super(exceptionEnum.getMsg());
        this.message = exceptionEnum.getMsg();
        this.code = exceptionEnum.getCode();
    }

    public QysException(QysLang qysLang,Object... args) {
        super(SpringUtils.getBean(MessageServer.class).getMsg(qysLang,args));
        this.message = super.getMessage();
        this.code = qysLang.getCode();
    }

}

